package cn.szabadsag.pet.service.impl;

import cn.szabadsag.base.service.impl.BaseServiceImpl;
import cn.szabadsag.pet.domain.Pet;
import cn.szabadsag.pet.mapper.PetDetailMapper;
import cn.szabadsag.pet.mapper.PetMapper;
import cn.szabadsag.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PetServiceImpl  extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetMapper petMapper;

    @Autowired
    private PetDetailMapper petDetailMapper;

    /**
     * 宠物领养下架
     * @param list
     */
    @Override
    public void offsale(List<Long> list) {
        petMapper.offsale(list);
    }

    /**
     * 宠物领养上架
     * @param list
     */
    @Override
    public void onsale(List<Long> list) {
        petMapper.onsale(list);
    }

    @Override
    public Pet loadByIdDetail(Long id) {
        return petMapper.loadByIdDetail(id);
    }


    /**
     * 新增宠物领养
     */
    @Override
    public void save(Pet pet) {
        //获取当前的登录用户【Employee】
        pet.setShop_id(27L);
        super.save(pet);
        //设置关联属性
        //  设置pet_id
        pet.getDetail().setPet_id(pet.getId());
        petDetailMapper.save(pet.getDetail());
    }
}
